﻿using System;
using System.Drawing;

namespace AppRPG.PhysObject
{
    public abstract class PhysObject
    {
        private float _elapsedTime;

        protected float TimeToUpdate;

        protected string Name;

        protected Image Texture;

        protected Point Position;
        protected Size Dimension;

        private void AddToElapsedTime(float deltaTime)
        {
            _elapsedTime += deltaTime;
        }

        protected abstract void MakeActions();
        public abstract void Interactive();

        public string GetObjectName()
        {
            return Name;
        }

        public Point GetPosition()
        {
            return Position;
        }

        public Size GetDimension()
        {
            return Dimension;
        }

        public void SetName(string name)
        {
            Name = name;
        }

        public void SetPosition(Point objectPosition)
        {
            Position = new Point(objectPosition.X, objectPosition.Y);
        }

        public void SetDimension(Size objectSize)
        {
            Dimension = new Size(objectSize.Width, objectSize.Height);
            object tag = Texture.Tag;
            Texture = new Bitmap(Texture, objectSize);
            Texture.Tag = tag;
        }

        public void SetTexture(Image objectTexture)
        {
            Texture = new Bitmap(objectTexture, Dimension);
            Texture.Tag = objectTexture.Tag;
        }

        public Image GetTexture()
        {
            return Texture;
        }

        public void Update(float deltaTime)
        {
            AddToElapsedTime(deltaTime);

            if (_elapsedTime >= TimeToUpdate)
            {
                MakeActions();
            }
        }

        public void Draw(Graphics graphics)
        {
            graphics.DrawImage(Texture, Position);
        }
    }
}
